package com.example.server.service;


import com.example.server.domain.Maintenance;
import com.example.server.mapper.MaintenanceMapper;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


@Service
public class MaintenanceService {

    private final MaintenanceMapper maintenanceMapper;

    public MaintenanceService(MaintenanceMapper maintenanceMapper) {
        this.maintenanceMapper = maintenanceMapper;
    }
    public void createMaintenance(Maintenance maintenance) {
        maintenanceMapper.insert(maintenance);
    }

    public void deleteMaintenance(Long id) {
        maintenanceMapper.deleteByPrimaryKey(id);
    }

    public Maintenance getMaintenanceById(Long id) {
        return maintenanceMapper.selectByPrimaryKey(id)   ;
    }

    public void updateMaintenance(Maintenance maintenance) {
        maintenanceMapper.updateByPrimaryKey(maintenance);

    }

    public List<Maintenance> getAllMaintenance() {

        return maintenanceMapper.selectAll();
    }

    public List<Maintenance> querylike(String content) {

        Example example = new Example(Maintenance.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("content", "%" + content + "%");
        return maintenanceMapper.selectByExample(example);

    }


    public void resolveMaintenance(Long id) {
        maintenanceMapper.resolveMaintenance(id);

    }
}
